﻿package fab.controls.forms 
{
	/**
	 * ...
	 * @author fab
	 */
	public class Birthday
	{
		static public function calculateAge(birthdate:Date):Number
		{
			var dtNow:Date = new Date();// gets current date
			var currentMonth:Number = dtNow.getMonth();
			var currentDay:Number = dtNow.getDay();
			var currentYear:Number = dtNow.getFullYear();
		 
			var bdMonth:Number = birthdate.getMonth();
			var bdDay:Number = birthdate.getDay();
			var bdYear:Number = birthdate.getFullYear();
		 
			// get the difference in years
			var years:Number = dtNow.getFullYear() - birthdate.getFullYear();
			// subtract another year if we're before the
			// birth day in the current year
			if (currentMonth < bdMonth || (currentMonth == bdMonth && currentDay < bdDay)) {
				years--;
			}
			return years;
		}
		/*
		 * MM/DD/YYYY to Date
		 * */
		static public function dateStringToObject(dateString:String):Date
		{
			var date_ar:Array = dateString.split("/");
			return new Date(date_ar[2],date_ar[0] - 1,date_ar[1]);
		}
	}
}